
import Mock from 'mockjs'

const HTTP_CONSTS ={
  AuthKey: {
    ADMIN: "GTMC-ADMIN-TOKEN", 
  },
  OPENID_KEY: "OpenId",
  CODE: {
    SUCCESS: 0,
    AUTH_ERROR: 70008,
  },
  HttpMethod: {
    PST: 'post',
    GET: 'get',
    PUT: 'put',
    DEL: 'delete',
    POST: 'post',
    DELETE: 'delete',
  }
}


/******
 * 
 * 表格字段，单行三点
 * 
 */

const MOCK_ID = '@natural(1000000000000000000, 2000000000000000000)'
const MOCK_NUM = 'N@natural(1000000000000000000, 2000000000000000000)'
const MOCK_CNAME = '@ctitle(2,16)'
const MOCK_CODE = '@string("upper", 9, 9)'
const MOCK_DESCRIPTION = '@cparagraph(3)'
const MOCK_DATETIME = '@datetime("yyyy-MM-dd HH:mm:ss")'
const MOCK_PRICE = '@float(0, 1000, 0, 6)'
const MOCK_IMAGE = '@image("50x50", "#324157", "#FFF", "png", "M")'
const MOCK_USER = '@cname'
const MOCK_MOBILE = '15@natural(800000000, 900000000)'
const MOCK_STATUS = '@natural(1, 6)'
const MOCK_TYPE = '@natural(1, 6)'
const MOCK_SORT = '@natural(1, 1000)'
const MOCK_QUANTITY = '@natural(1, 100)'
const MOCK_BOOLEAN = '@boolean(5, 5, true)'


function getMockEntity(firstId) {
  return {
    "versionId|+1": parseInt(firstId),
    "seriesCode": '@string("lower", 10, 10)',
    "name": MOCK_CNAME,
    "code": '@integer(0)', //随机整数
    "description": MOCK_DESCRIPTION,
    "status": MOCK_STATUS,
    "createBy": '@string("lower", 10, 30)',
    "createTime": MOCK_DATETIME,
    "updateBy": '@string("lower", 10, 30)',
    "updateTime": MOCK_DATETIME,

    "adminName": MOCK_CNAME,
    "vehName": '@ctitle(5,7)',
    "vehNameCode": '@string("upper", 6, 6)',
    "modelCode": '@string("upper", 5, 5)-@string("upper", 5, 5)',

    // "sourceType": "1000000058",
    "sourceType": "森林防火救援队伍",
    "sourceLevel": "1000000056",
    "jobLevel": "1000000055",
    "resourceType":"1000000031",

    "adminType": 1,
    "areaCode": "150000000000",
    "areaName": "内蒙古自治区",
    "createdBy": "system",
    "createdTime": 1688628446000,
    "csAdminLevel": "Province",
    "id": "1",
    "job": "自治区超级管理员",
    "menuPermission":"1000000001,1000000002,1000000006,1000000003:2000000001:",
    "name": "系统管理员",
    "orgId": "dp-10aa1969bd094b05bdfa764126fc6210",
    "orgName": "自治区指挥体系",
    "phone": "13129575964",
    "status": 1,
    "udOrder": 1,
    "updatedBy": "system",
    "updatedTime": 1688628461000,

    "manualId": MOCK_ID,
    "itemId": MOCK_ID,
    "itemName": MOCK_CNAME,
    "seriesId": MOCK_ID,
    "partsTypeId": MOCK_ID,

    "partsId": MOCK_ID,
    "partsName": MOCK_CNAME,
    "partsCode": MOCK_CODE,
    "partsTypeName": MOCK_CNAME,
    "suggestPrice": MOCK_PRICE,
    "iconPath": MOCK_IMAGE,
    "tipsPaths": `["${MOCK_IMAGE}","${MOCK_IMAGE}"]`,
    "orderNo": MOCK_NUM,
    "agencyName": MOCK_CNAME,
    "jobOrderNo": MOCK_NUM,
    "completionTime": MOCK_DATETIME,
    "omsOrderNo": MOCK_NUM,
    "omsThirdPartySerialNo": MOCK_NUM,
    "receivableAmount": MOCK_PRICE,
    "moneyReceived": MOCK_PRICE,
    "discountAmount": MOCK_PRICE,


    "maintainOrderNo": MOCK_NUM,
    "vehicleName": MOCK_CNAME,
    "maintainName": MOCK_CNAME,
    "customerName": MOCK_USER,
    "customerPhoneNumber": MOCK_MOBILE,


    "username": MOCK_CODE,
    "fullName": MOCK_USER,
    "mobile": MOCK_MOBILE,
    "position": MOCK_CNAME,
    "dept": MOCK_CNAME,

    "articleId": MOCK_ID,
    "typeName": MOCK_CNAME,
    "scenarioName": MOCK_CNAME,
    "scenarioId": MOCK_ID,
    "title": MOCK_CNAME,
    "content": MOCK_DESCRIPTION,

    maintainManualId: MOCK_ID,
    entityId: MOCK_ID,
    eventId: "",
    eventType: MOCK_TYPE,
    manualId: MOCK_ID,
    manualItemRules: [],
    manualItems: [],
    manualType: "",
    modelCode: MOCK_CODE,
    name: MOCK_CNAME,
    sort: MOCK_SORT,
    vehName: MOCK_CNAME,
    vehNameCode: MOCK_CODE,

    manualType: MOCK_TYPE,
 
    orderId: MOCK_ID,
    orderNum: MOCK_NUM,
    actualAmount: MOCK_PRICE,
    buyerName: MOCK_USER,
    buyerMobile: MOCK_MOBILE,
    buyerVehName: MOCK_CNAME,
    buyerLicensePlateNum: MOCK_CODE,
    storeName: MOCK_CNAME,
    storeCode: MOCK_CODE,

    ordPaymentVo: {

      omsOrderNo: MOCK_NUM,
      omsThirdPartySerialNo: MOCK_NUM,
    },
    buyerMessage: MOCK_DESCRIPTION,
    refundReason: MOCK_DESCRIPTION,
    refundAmount: MOCK_PRICE,

    buyerLicensePlateNum: MOCK_CODE,
    buyerModelCode: MOCK_CODE,
    buyerVehFrameCode: MOCK_CODE,
    storeName: MOCK_CNAME,
    storeCode: MOCK_CODE,
    storeAddress: MOCK_DESCRIPTION,
    orderAmount: MOCK_PRICE,
    scheduledTime: MOCK_DATETIME,
 

    token: "sfasdfasdf" 
  }

}




let adminMap={
  "19520685565":{ 
    // adminType:"7",
    menuPermission:"1000000001,1000000002,1000000006,1000000003::"
  },
  "15800010001":{
    adminType:"9",
    menuPermission:"1000000001::"
  },
  // 救援队伍
  "15800050010":{
    adminType:17,
    pageType:2,
    menuPermission:"1000000007,1000000008,1000000010::"
  },
  "15800030001":{
    adminType:7,
    menuPermission:"1000000007,1000000008,1000000013::"
  },
  "15800040001":{
    adminType:13,
    menuPermission:"1000000007,1000000008,1000000013::"
  },
  //避难场所
  "15800050014":{
    adminType:14,
    pageType:2,
    menuPermission:"1000000007,1000000006,1000000014::"
  }, 
}


export default {

  login(data, suc, err) {
    let body=JSON.parse(data.body) 
    let res = Mock.mock({
      "data": getMockEntity(100000) , 
      "code": HTTP_CONSTS.CODE.SUCCESS,
    });  
    res.data.phone=body.phone 
    Object.assign(res.data, adminMap[body.phone] ) 
    return res;
  },

  list(data, suc, err) {
    let res = Mock.mock({
      "data|10": [
        getMockEntity(100000)
      ],
      "header": {
      },
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });
    return res;
  },


  page(data, suc, err) {
    let param = JSON.parse(data.body);
    let total = 998;
    let firstId = (param.current * param.size + 1)

    let res = Mock.mock({
      "data": {
        "current": param.current,
        "pages": parseInt(total / param.size) + 1,
        "records|10": [
          getMockEntity(firstId)
        ],
        "size": param.size,
        "total": total,
      },
      "header": {
      },
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });

    return res;
  },


  add(data, suc, err) {
    let param = JSON.parse(data.body);

    let res = Mock.mock({
      "data": '@natural(5000000000000, 6000000000000)',
      "header": {
      },
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });
    return res;
  },

  modify(data, suc, err) {
    let param = JSON.parse(data.body);
    let res = Mock.mock({
      "data": '@natural(4000000000000, 5000000000000)',
      "header": {
      },
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });
    return res;
  },

  saveList(data, suc, err) {
    let param = JSON.parse(data.body);
    let res = Mock.mock({
      "data|10": [
        '@natural(5000000000000, 6000000000000)'
      ],
      "header": {
      },
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });
    return res;
  },

  saveReturnId(data, suc, err) {
    let param = JSON.parse(data.body);
    let res = Mock.mock({
      "data": '@natural(5000000000000, 6000000000000)',
      "header": {
      },
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });
    return res;
  },


  saveReturnTrue(data, suc, err) {
    let param = JSON.parse(data.body);

    let res = Mock.mock({
      "data": true,
      "header": {
      },
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });
    return res;
  },

  delete(data, suc, err) {

    let res = Mock.mock({
      "data": true, 
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });
    return res;
  },

  get(data, suc, err) {

    let res = Mock.mock({
      "data": getMockEntity(800000000000), 
      "code": HTTP_CONSTS.CODE.SUCCESS,
      "success": true,
    });

    return res;
  },




}
